import concurrent.futures
import time

def task(n):
    # 模拟一个耗时任务
    time.sleep(2)
    return f"任务{n}完成"

# 创建一个进程池
with concurrent.futures.ProcessPoolExecutor(max_workers=5) as executor:
    # 提交任务
    futures = [executor.submit(task, i) for i in range(10)]

    # 获取任务结果
    for future in concurrent.futures.as_completed(futures):
        try:
            print(future.result())
        except Exception as e:
            print(f"异常：{e}")